import Vue from 'vue'
import Router from 'vue-router'
// 组织架构
import departmentsRouter from '@/router/departments(组织架构).js'
// 员工设置
import employeesRouter from '@/router/employees(员工管理).js'
// 公司设置
import settingsRouter from '@/router/settings(公司设置).js'
// 工资
import salarysRouter from '@/router/salarys(工资).js'
// 社保
import socialSecuritysRouter from '@/router/socialsecuritys(社保).js'
// 考勤
import attendancesRouter from '@/router/attendances(考勤)'
// 审批
import approvalsRouter from '@/router/approvals(审批)'
// 权限管理
import permissionsRouter from '@/router/permissions(权限管理)'
// 文件导入
import importRouter from "@/router/import(文件导入)"
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import store from '@/store'
// 创建路由规则
// 动态路由表
export const asyncRoutes = [
  // 组织架构
  departmentsRouter,
  // {
  //   path: '/departments',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       name: 'departments',
  //       component: () => import('@/views/departments(组织架构)/departments.vue')
  //     }
  //   ]
  // },
  //员工管理
  employeesRouter,
  // 公司设置
  settingsRouter,
  // 工资
  salarysRouter,
  // 社保
  socialSecuritysRouter,
  // 考勤
  attendancesRouter,
  // 审批
  approvalsRouter,
  // 权限管理
  permissionsRouter,
  // 文件导入
  importRouter
]
// 静态路由表
export const constantRoutes = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName:"login"*/'@/views/login/index'),
    hidden: true
  },


  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import(/* webpackChunkName:"dashboard"*/'@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName:"404"*/'@/views/404'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

// 路由注册
const createRouter = () => new Router({
  // 却换到history模式  默认是hash
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 指定路由规则,生成路由表
  routes: [...constantRoutes]
})

const router = createRouter()

// 清理路由信息: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
// 导出路由实例
export default router
